/**
*
*动画类,根据2d动画来控制3d动画,
*3d.x=2d.x
*3d.z=-2d.y
*3d._yrotation=2d.rotation
*
*这个是根据在flash开发环境里写的动画来控制的
*/

package kgame5.k3d.util3d {
import kgame5.k3d.core.obj3d.node3d.Node3D;

import flash.display.*;
import flash.events.*;

public class AnimTrack3D_Flash extends AnimTrack3D{
	//____________________Property______________________
	
	private var 
		iStartFrameIdx:int,//动画开始的真
		iEndFrameIdx:int;//结束的真
		
	private var md:Node3D;//本次运动的模型
	
	private var bOK:Boolean=false;
	//____________________Method____________________
	public function AnimTrack3D_Flash(p_mc_track:MovieClip){
		super(p_mc_track);
	}
	//把一个md放在mc标志的位置
	override public function place(p_md:Node3D,iAimFrameIdx:int){
		//目标位置
		mc_track.gotoAndStop(iAimFrameIdx);
		p_md.x=mc_track.mc.x;
		p_md.z=-mc_track.mc.y;
		p_md.rotY= mc_track.mc.rotation;
		
		mc_track.removeEventListener(Event.ENTER_FRAME, efh);
		
		bOK=false;
	}
	override public function start(p_md:Node3D,p_startFrameIdx:int,p_endFrameIdx:int){
		md=p_md;
		
		iStartFrameIdx=p_startFrameIdx;
		iEndFrameIdx=p_endFrameIdx;
		
		
		mc_track.gotoAndPlay(iStartFrameIdx);
		
		//~这个很重要，在start 的时候需要设置好位置，否则会有抖动的现象
		md.x=mc_track.mc.x;
		md.z=-mc_track.mc.y;
		md.rotY= mc_track.mc.rotation;
		
		mc_track.removeEventListener(Event.ENTER_FRAME, efh);
		mc_track.addEventListener(Event.ENTER_FRAME, efh);
		
		bOK=false;
	}
	private  function efh(e:Event){
		
		md.x=mc_track.mc.x;
		md.z=-mc_track.mc.y;
		md.rotY= mc_track.mc.rotation;
		
		if(mc_track.currentFrame==iEndFrameIdx){
			bOK=true;
			mc_track.removeEventListener(Event.ENTER_FRAME, efh);
			
			this.notifyOK();
		}
	}
	
	override public function isOK():Boolean{
		return bOK;
	}
}//end of class
}
